/*
 * @Author: your name
 * @Date: 2021-05-24 10:45:06
 * @LastEditTime: 2021-05-24 10:54:53
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \data-structure\01.add-one-to-hundred.js
 */

// 算法的重要性

/**
 * for one to hundred
 * @param {Number} n 
 * @returns {Number}
 */

function sum1(n) {
    let sum = 0;
    for (let i = 1; i <= n; i++) {
        sum += i;
    }
    return sum;
}
/**
 * gauss one to hundred
 * @param {Number} n 
 * @returns {Number}
 */

function sum2(n) {
    let sum = (1 + n) * n / 2;
    return sum;
}

console.time('sum1')
console.log(sum1(10000))
console.timeEnd('sum1')
console.time('sum2')
console.log(sum2(10000))
console.timeEnd('sum2')

